package com.ruoyi.app.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.app.domain.ShopCustomer;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.app.domain.ShopSupplier;
import com.ruoyi.app.service.IShopSupplierService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 供应商信息Controller
 * 
 * @author zhangkaiqiang
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/shop/supplier")
public class ShopSupplierController extends BaseController
{
    @Autowired
    private IShopSupplierService shopSupplierService;

    /**
     * 查询供应商信息列表
     */
//    @PreAuthorize("@ss.hasPermi('shop:supplier:list')")
    @GetMapping("/list")
    public AjaxResult list(ShopSupplier shopSupplier)
    {
//        startPage();
        shopSupplier.setShopId(getShopId());
        List<ShopSupplier> list = shopSupplierService.selectShopSupplierList(shopSupplier);
        return success(getDataTable(list));
    }

    /**
     * 导出供应商信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:supplier:export')")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopSupplier shopSupplier)
    {
        List<ShopSupplier> list = shopSupplierService.selectShopSupplierList(shopSupplier);
        ExcelUtil<ShopSupplier> util = new ExcelUtil<ShopSupplier>(ShopSupplier.class);
        util.exportExcel(response, list, "供应商信息数据");
    }

    /**
     * 获取供应商信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('shop:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(shopSupplierService.selectShopSupplierById(id));
    }

    /**
     * 新增供应商信息
     */
//    @PreAuthorize("@ss.hasPermi('shop:supplier:add')")
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ShopSupplier shopSupplier)
    {
        return toAjax(shopSupplierService.save(shopSupplier));
    }

    /**
     * 修改供应商信息
     */
//    @PreAuthorize("@ss.hasPermi('shop:supplier:edit')")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ShopSupplier shopSupplier)
    {
        return toAjax(shopSupplierService.updateById(shopSupplier));
    }

    /**
     * 删除供应商信息
     */
//    @PreAuthorize("@ss.hasPermi('shop:supplier:remove')")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(shopSupplierService.removeByIds(objects));
    }

    /**
     * 修改客户信息
     */
//    @PreAuthorize("@ss.hasPermi('shop:shop/customer:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody ShopSupplier shopSupplier)
    {
        shopSupplier.setShopId(getShopId());
        String a = shopSupplierService.addOrUpdate(shopSupplier);
        return AjaxResult.success().setData(a);
    }
}
